package org.jeecg.modules.activiti.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.activiti.entity.FormDesignData;
import org.jeecg.modules.activiti.mapper.FormDesignDataMapper;
import org.jeecg.modules.activiti.service.IFormDesignDataService;
import org.jeecg.modules.activiti.util.UserUtil;
import org.jeecg.modules.system.util.SecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: 自定义表单
 * @author: 黄劲博
 * @date: 2021/6/25 14:20
 */
@RestController
@RequestMapping("/formDesignData")
@Api(tags = "自定义表单")
public class FormDesignDataController {

    @Autowired
    private FormDesignDataMapper formDesignDataMapper;
    @Autowired
    private IFormDesignDataService iFormDesignDataService;
    @Autowired
    private UserUtil userUtil;

    @GetMapping("/info/FormDesignId/{FormDesignId}/actId/{actId}")
    @ApiOperation("工作流模型分页")
    @AutoLog
    public Object getFormDesign(@PathVariable String FormDesignId, @PathVariable String actId) {
        return Result.ok(iFormDesignDataService.getById(FormDesignId));
    }

    @GetMapping("/info/{id}")
    @ApiOperation("工作流模型分页")
    @AutoLog
    public Object getById(@PathVariable String id) {
        return Result.ok(iFormDesignDataService.getById(id));
    }

    /**
     * @Description: TODO
     * @param: id: FormDesignID
     * @Return: java.lang.Object 
     * @author: 黄劲博
     * @date: 2021/7/9 19:00
    */
    @GetMapping("/hongData/{id}")
    @ApiOperation("工作流模型分页")
    @AutoLog
    public Object getHongData(@PathVariable String id) {
        return Result.ok(iFormDesignDataService.getHongData(id));
    }

    @PostMapping("/saveData")
    @ResponseBody
    @ApiOperation("保存表单值")
    @AutoLog
    public Object createModel( FormDesignData formDesignData) {
        Result<FormDesignData> result = new Result<>();
        formDesignData.setCreateId(userUtil.getCurrUser().getId());
        formDesignData.setCreateBy(userUtil.getCurrUser().getUsername());
        if (iFormDesignDataService.save(formDesignData)) {
            result.setResult(formDesignData);
            result.setMessage("保存表单值操作成功");
            result.setCode(200);
        } else {
            result.setResult(formDesignData);
            result.setMessage("保存表单值操作失败");
            result.setCode(200);
        }
        return result;
    }

}
